from bs4 import BeautifulSoup
import requests
import re

# ----------------------通过标签及其属性来获取元素-------------------------------
response=requests.get("https://morvanzhou.github.io/static/scraping/list.html")
response.encoding="utf-8"
print(response.status_code)
# print(response.text)
soup=BeautifulSoup(response.text,"html.parser")
# 查找<li class='mouth'>元素的数组
mouth=soup.find_all('li', {"class": "month"})
print(mouth)
for m in mouth:
    print(m.get_text())

# ----------------------通过正则表达式-------------------------------
resp=requests.get("https://morvanzhou.github.io/static/scraping/table.html")
print(resp.status_code)
soup=BeautifulSoup(resp.text,'html.parser')
img_links=soup.find_all("img",{"src":re.compile(".*?\.jpg")})
for link in img_links:
    print(link['src'])